<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>职位详情</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>

    <script type="text/javascript" src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type="text/javascript" src='../js/libs/sui/sm.js' charset='utf-8'></script>
    <script type="text/javascript" src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type="text/javascript" src="../js/libs/juicer-min.js"></script>
    <script type="text/javascript" src="../js/libs/jquery.md5.js"></script>
    <script type="text/javascript" src="../js/api.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<div class="content native-scroll bg-default p-t22">
    <!--头部-->
    <div class="head-no-toolbar bg-self-green no-left-icon">
        <span class="icon iconfont c-white p-l" onclick="javascript:closeWin();">&#xe61f;</span>
        <span class="c-white t-center">职位详情</span>
    </div>
    <!--招聘职位详情-->
    <div id="cy-post-detail" class="career-panel bg-white">
        <!--
        <div class="row">
            <div class="col-60">Java软件工程师</div>
            <div class="col-40 t-right c-red">6千-8千</div>
        </div>
        <div class="row c-gray">
            <div class="col-60">贵州安云科技有限公司</div>
            <div class="col-40 t-right">今天</div>
        </div>
        <div class="f-little">
            <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe614;</i><span>贵阳</span></span>
            <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe618;</i><span>2-5年</span></span>
            <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe61a;</i><span>学历不限</span></span>
            <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe60f;</i><span>全职</span></span>
            <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe619;</i><span>3人</span></span>
        </div>
        <div class="benefit-panel c-gray t-center">
            <div class="item1">
                <div class="bg-default">五险一金</div>
            </div>
            <div class="item1 bg-default">
                <div class="bg-default">年底双薪</div>
            </div>
            <div class="item1 bg-default">
                <div class="bg-default">绩效奖金</div>
            </div>
            <div class="item1 bg-default">
                <div class="bg-default">全勤奖</div>
            </div>
            <div class="item1 bg-default">
                <div class="bg-default">交通补助</div>
            </div>
            <div class="item1 bg-default">
                <div class="bg-default">餐补</div>
            </div>
        </div>
        <div class="list-block">
            <ul>
                <li class="item-content item-link">
                    <div class="item-media"><i class="iconfont icon c-blue">&#xe614;</i></div>
                    <div class="item-inner">
                        <div class="item-subtitle">贵州贵阳国家高新区金阳科技产业园标准厂房辅助用房B514室</div>
                    </div>
                </li>
            </ul>
        </div>
        -->
    </div>
    <!--职位描述-->
    <div class="job-descript bg-white">
        <div class="f-bold border-b">职位描述</div>
        <div id="cy-post-desc" class="c-gray"></div>
        <!--
        <ol class="c-gray">
            <li>两年以上Java项目开发经验；熟悉Java语言和IntelliJ IDEA或Eclipse开发环境，熟悉面向对象开发思想；</li>
            <li>熟练掌握 HTML、CSS 3、Ajax、jQuery、JavaScript 等 Web 前端技术；</li>
            <li>熟悉Java各种主流框架，如：Struts2、Spring、Hibernate、MyBatis等，熟悉SpringMVC者优先考虑；</li>
            <li>熟悉SQL常用语法，能进行简单数据库维护，熟悉常用数据库Oracle、MySQL、SQL Server等。</li>
        </ol>
        -->
        <div class="attention c-gray">
            <span class="c-red">*</span>注意：向应聘者收取任何费用都属违法行为，请提高警惕！！！
        </div>
    </div>
    <!--底部按钮-->
    <div class="botm-btn deliver-btn">
        <div id="send_resume_btn" class="left c-white t-center">投简历</div>
        <div id="unsend_resume_btn" class="left c-white t-center hide">取消投简历</div>
        <div class="right">
            <div id="apply-btn" class="right-btn t-center c-blue"><i class="icon iconfont">&#xe628;</i></div>
            <div id="unapply-btn" class="right-btn t-center c-blue hide"><i class="icon iconfont">&#xe627;</i></div>
        </div>
    </div>
</div>

<!-- 职位详细模版 -->
<script id="cy-post-detail-tpl" type="text/template">
    {@each postList as it1, index}
        <div class="row">
            {@if (it1.POST_NAME != null) && (it1.POST_NAME != '')}
                <div class="col-60">&{it1.POST_NAME}</div>
            {@/if}

            {@if (it1.PAY_REMARKS != null) && (it1.PAY_REMARKS != '')}
                <div class="col-40 t-right c-red">&{it1.PAY_REMARKS}</div>
            {@/if}
        </div>
        <div class="row c-gray">
            {@if (unitName != null) && (unitName != '')}
                <div class="col-60">&{unitName}</div>
            {@/if}

            {@if (beginDate != null) && (beginDate != '')}
                <div class="col-40 t-right">&{beginDate}</div>
            {@/if}
        </div>
        <div class="f-little">
            {@if (it1.LOCATION != null) && (it1.LOCATION != '')}
                <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe614;</i><span>&{it1.LOCATION}</span></span>
            {@/if}

            {@if (it1.EXPERIENCE_REQ != null) && (it1.EXPERIENCE_REQ != '')}
                <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe618;</i><span>&{it1.EXPERIENCE_REQ}</span></span>
            {@/if}

            {@if (it1.EDUCATION_REQ != null) && (it1.EDUCATION_REQ != '')}
                <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe61a;</i><span>&{it1.EDUCATION_REQ}</span></span>
            {@/if}

            {@if (it1.FULLTIME != null) && (it1.FULLTIME == 0)}
                <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe60f;</i><span>兼职</span></span>
            {@else if (it1.FULLTIME != null) && (it1.FULLTIME == 1)}
                <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe60f;</i><span>全职</span></span>
            {@/if}

            {@if (it1.RECRUIT_CNT != null) && (it1.RECRUIT_CNT != '')}
                <span class="m-r"><i class="iconfont icon employ-icon c-blue">&#xe619;</i><span>&{it1.RECRUIT_CNT}人</span></span>
            {@/if}
        </div>
        <div class="benefit-panel c-gray t-center">
            {@each welfareList as it2, index}
                {@if (it2 != null) && (it2 != '')}
                    <div class="item1 bg-default">
                        <div class="bg-default">&{it2}</div>
                    </div>
                {@/if}
            {@/each}
        </div>

        {@if (unitAddr != null) && (unitAddr != '')}
            <div class="list-block">
                <ul>
                    <li class="item-content item-link">
                        <div class="item-media"><i class="iconfont icon c-blue">&#xe614;</i></div>
                        <div class="item-inner">
                            <div class="item-subtitle">&{unitAddr}</div>
                        </div>
                    </li>
                </ul>
            </div>
        {@/if}
    {@/each}
</script>

<!-- 职位描述模版 -->
<script id="cy-post-desc-tpl" type="text/template">
    {@each postList as it, index}
        {@if (it.POST_DESC != null) && (it.POST_DESC != '')}
            $${it.POST_DESC}
        {@/if}
    {@/each}
</script>

<script type="text/javascript">
    apiready = function() {
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });

        // 获取职位 SQL
        var sql1 = "SELECT T3.*, T4.WELFARE FROM E_RECRUIT_POST T3 LEFT JOIN (SELECT T1.POST_ID, GROUP_CONCAT(T2.CODE_NAME SEPARATOR ',') AS WELFARE ";
        sql1 += "FROM E_POST_EXPLAIN T1 LEFT JOIN SU_CODE_BASE T2 ON T1.CODE = T2.CODE_ID WHERE T2.STATE = 'A' AND T2.CODE_TYPE = 'POST_CODE' ";
        sql1 += "GROUP BY T1.POST_ID) T4 ON T3.POST_ID = T4.POST_ID WHERE T3.POST_ID = '{0}'";
        // 获取已收藏职位的收藏 ID SQL
        var sql2 = "SELECT GROUP_CONCAT(T.APPLY_ID SEPARATOR ',') AS APPLY_IDS FROM E_APPLY_POST T WHERE T.STATE = '1' ";
        sql2 += "AND T.STUDENT_ID = '{0}' AND T.UNIT_ID = '{1}' AND T.POST_ID = '{2}' GROUP BY T.STUDENT_ID, T.UNIT_ID, T.POST_ID";
        // 收藏的 SQL
        var sql3 = "INSERT INTO E_APPLY_POST(STUDENT_ID, UNIT_ID, POST_ID, STATE, APPLY_DATE, CANCEL_DATE) VALUES('{0}', '{1}', '{2}', 1, NOW(), NULL)";
        // 取消收藏的 SQL
        var sql4 = "UPDATE E_APPLY_POST T SET T.STATE = '0', T.CANCEL_DATE = NOW() WHERE T.APPLY_ID IN ({0})";
        // 查询简历 ID
        var sql5 = "SELECT T.RESUME_ID FROM E_RESUME T WHERE T.STUDENT_ID = '{0}'";
        // 查询是否已过简历给该职位的投简历 ID SQL
        var sql6 = "SELECT GROUP_CONCAT(T1.APPLY_ID SEPARATOR ',') AS SEND_APPLY_IDS FROM E_APPLY_POST T1, E_RESUME T2 WHERE T1.STATE = '2' ";
        sql6 += "AND T1.STUDENT_ID = T2.STUDENT_ID AND T1.STUDENT_ID = '{0}' AND T1.UNIT_ID = '{1}' AND T1.POST_ID = '{2}' GROUP BY T1.STUDENT_ID, T1.UNIT_ID, T1.POST_ID";
        // 投简历的 SQL
        var sql7 = "INSERT INTO E_APPLY_POST(STUDENT_ID, UNIT_ID, POST_ID, STATE, APPLY_DATE, CANCEL_DATE) VALUES('{0}', '{1}', '{2}', 2, NOW(), NULL)";
        // 取消投简历的 SQL
        var sql8 = "UPDATE E_APPLY_POST T SET T.STATE = '3', T.CANCEL_DATE = NOW() WHERE T.APPLY_ID IN ({0})";
        // 获取登录学生的信息
        var stuInfo = null;
        // 已收藏职位的收藏 ID
        var applyIds = null;
        // 已投过简历给该职位的投简历 ID
        var sendApplyIds = null;
        // 简历 ID
        var resumeId = null;
        // 收藏标志。true-可以收藏；false-不可以收藏
        var applyFlag = false;
        // 取消收藏标志。true-可以取消收藏；false-不可以取消收藏
        var unapplyFlag = false;
        // 投简历标志。true-可以投简历；false-不可以投简历
        var sendResumeFlag = false;
        // 取消投简历标志。true-可以取消投简历；false-不可以取消投简历
        var unsendResumeFlag = false;

        if (isNotEmpty(api.pageParam.unitId) && isNotEmpty(api.pageParam.postId)) {
            if (isLogin()) {
                stuInfo = getLoginStudentInfo();
            }

            /**
             *
             * 获取收藏 ID。
             *
             * @param isLoading 是否显示等待框
             *
             */
            function getApplyIds(isLoading) {
                if (isLogin()) {
                    if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                        var tmpSql2 = sql2.format(stuInfo.STUDENT_ID, api.pageParam.unitId, api.pageParam.postId);

                        // 查询是否已收藏该职位
                        dbQuery(1, 1, tmpSql2, isLoading, function(ret, err) {
                            // 查询成功
                            if (isObject(ret) && (ret.statusCode == 0)) {
                                // 如果收藏 ID 不为空，表示已收藏该职位
                                if (isArray(ret.result) && (ret.result.length > 0) && isNotEmpty(ret.result[0].APPLY_IDS)) {
                                    applyIds = ret.result[0].APPLY_IDS;

                                    applyFlag = false;
                                    unapplyFlag = true;

                                    $("#apply-btn").addClass("hide");
                                    $("#unapply-btn").removeClass("hide");

                                    // 否则，表示未收藏该公司
                                } else {
                                    applyFlag = true;
                                    unapplyFlag = false;

                                    $("#apply-btn").removeClass("hide");
                                    $("#unapply-btn").addClass("hide");
                                }

                                // 查询失败
                            } else {
                                applyFlag = false;
                                unapplyFlag = false;

                                $("#apply-btn").addClass("hide");
                                $("#unapply-btn").addClass("hide");
                            }
                        });
                    }
                }
            }

            /**
             *
             * 获取简历 ID。
             *
             * @param isLoading 是否显示等待框
             *
             */
            function getResumeId(isLoading) {
                if (isLogin()) {
                    if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                        var tmpSql5 = sql5.format(stuInfo.STUDENT_ID);

                        // 查询是否已创建简历
                        dbQuery(1, 1, tmpSql5, isLoading, function(ret, err) {
                            // 查询成功
                            if (isObject(ret) && (ret.statusCode == 0)) {
                                // 如果简历 ID 不为空，表示已投过该职位
                                if (isArray(ret.result) && (ret.result.length > 0) && isNumber(ret.result[0].RESUME_ID)) {
                                    resumeId = ret.result[0].RESUME_ID;
                                }

                                // 查询失败
                            } else {
                                sendResumeFlag = false;
                                unsendResumeFlag = false;

                                $("#send_resume_btn").addClass("hide");
                                $("#unsend_resume_btn").addClass("hide");
                            }
                        });
                    }
                }
            }

            /**
             *
             * 获取投简历 ID。
             *
             * @param isLoading 是否显示等待框
             *
             */
            function getSendApplyIds(isLoading) {
                if (isLogin()) {
                    if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                        var tmpSql6 = sql6.format(stuInfo.STUDENT_ID, api.pageParam.unitId, api.pageParam.postId);

                        // 查询是否已收藏该职位
                        dbQuery(1, 1, tmpSql6, isLoading, function(ret, err) {
                            // 查询成功
                            if (isObject(ret) && (ret.statusCode == 0)) {
                                // 如果投简历 ID 不为空，表示已投过简历给该职位
                                if (isArray(ret.result) && (ret.result.length > 0) && isNotEmpty(ret.result[0].SEND_APPLY_IDS)) {
                                    sendApplyIds = ret.result[0].SEND_APPLY_IDS;

                                    sendResumeFlag = false;
                                    unsendResumeFlag = true;

                                    $("#send_resume_btn").addClass("hide");
                                    $("#unsend_resume_btn").removeClass("hide");

                                    // 否则，表示未投过简历给该职位
                                } else {
                                    sendResumeFlag = true;
                                    unsendResumeFlag = false;

                                    $("#send_resume_btn").removeClass("hide");
                                    $("#unsend_resume_btn").addClass("hide");
                                }

                                // 查询失败
                            } else {
                                sendResumeFlag = false;
                                unsendResumeFlag = false;

                                $("#send_resume_btn").addClass("hide");
                                $("#unsend_resume_btn").addClass("hide");
                            }
                        });
                    }
                }
            }

            // 获取收藏 ID
            getApplyIds(true);
            // 获取简历 ID
            getResumeId(true);
            // 获取投简历 ID
            getSendApplyIds(true);

            // 查询职位信息
            var tmpSql1 = sql1.format(api.pageParam.postId);
            dbQuery(1, 1, tmpSql1, true, function (ret, err) {
                // 查询成功
                if (isObject(ret) && (ret.statusCode == 0)) {
                    var postData = {
                        url: getUrl(),
                        postList: ret.result,
                        unitName: api.pageParam.unitName,
                        unitAddr: api.pageParam.unitAddr,
                        beginDate: "",
                        welfareList: []
                    };

                    $.each(postData.postList, function (index, post) {
                        // 整理日期数据
                        if (isEmpty(post.BEGIN_DATE)) {
                            postData.beginDate = "";
                        } else {
                            postData.beginDate = new Date(post.BEGIN_DATE).format("M月d日");
                        }

                        // 整理福利数据
                        if (isNotEmpty(post.WELFARE)) {
                            postData.welfareList = post.WELFARE.split(",");
                        }

                        // 只循环一次即可
                        return false;
                    });

                    $("#cy-post-detail").html(juicer($("#cy-post-detail-tpl").html(), postData));
                    $("#cy-post-desc").html(juicer($("#cy-post-desc-tpl").html(), postData));
                }
            });

            // 点击投简历
            $("#send_resume_btn").click(function() {
                if (isLogin()) {
                    // 已创建简历
                    if (isNumber(resumeId)) {
                        if (sendResumeFlag) {
                            if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                                sendResumeFlag = false;

                                var tmpSql7 = sql7.format(stuInfo.STUDENT_ID, api.pageParam.unitId, api.pageParam.postId);

                                // 投简历
                                dbExecute(tmpSql7, true, function(ret, err) {
                                    // 执行成功
                                    if (isObject(ret) && (ret.statusCode == 0)) {
                                        toast("投简历成功");

                                        // 获取投简历 ID
                                        getSendApplyIds(true);

                                        // 发送投简历事件
                                        api.sendEvent({
                                            name: "resumeEvent"
                                        });

                                        // 执行失败
                                    } else {
                                        toast("投简历失败，稍后再试");

                                        sendResumeFlag = true;
                                        unsendResumeFlag = false;

                                        $("#send_resume_btn").removeClass("hide");
                                        $("#unsend_resume_btn").addClass("hide");
                                    }
                                });
                            }
                        }

                        // 未创建简历
                    } else {
                        toast("请先创建简历，再投")
                    }
                } else {
                    toLogin();
                }
            });

            // 点击取消投简历
            $("#unsend_resume_btn").click(function() {
                if (isLogin()) {
                    if (unsendResumeFlag) {
                        if (isNotEmpty(sendApplyIds)) {
                            unsendResumeFlag = false;

                            var tmpSendApplyIds = sendApplyIds.split(",");
                            var tmpSendApplyIdsStr= "";

                            for (var i = 0; i < tmpSendApplyIds.length; i++) {
                                if (tmpSendApplyIds.length == 1) {
                                    tmpSendApplyIdsStr += ("'" + tmpSendApplyIds[i] + "'");
                                } else {
                                    if (i < (tmpSendApplyIds.length - 1)) {
                                        tmpSendApplyIdsStr += ("'" + tmpSendApplyIds[i] + "',");
                                    } else {
                                        tmpSendApplyIdsStr += ("'" + tmpSendApplyIds[i] + "'");
                                    }
                                }
                            }

                            var tmpSql8 = sql8.format(tmpSendApplyIdsStr);

                            // 取消收藏
                            dbExecute(tmpSql8, true, function(ret, err) {
                                // 执行成功
                                if (isObject(ret) && (ret.statusCode == 0)) {
                                    toast("取消投简历成功");

                                    // 获取投简历 ID
                                    getSendApplyIds(true);

                                    // 发送投简历事件
                                    api.sendEvent({
                                        name: "resumeEvent"
                                    });



                                    // 执行失败
                                } else {
                                    toast("取消投简历失败，稍后再试");

                                    sendResumeFlag = false;
                                    unsendResumeFlag = true;

                                    $("#send_resume_btn").addClass("hide");
                                    $("#unsend_resume_btn").removeClass("hide");
                                }
                            });
                        }
                    }
                } else {
                    toLogin();
                }
            });

            // 点击收藏
            $("#apply-btn").click(function() {
                if (isLogin()) {
                    if (applyFlag) {
                        if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                            applyFlag = false;

                            var tmpSql3 = sql3.format(stuInfo.STUDENT_ID, api.pageParam.unitId, api.pageParam.postId);

                            // 收藏
                            dbExecute(tmpSql3, true, function(ret, err) {
                                // 执行成功
                                if (isObject(ret) && (ret.statusCode == 0)) {
                                    toast("收藏成功");

                                    // 获取收藏 ID
                                    getApplyIds(true);

                                    //发送收藏事件，在 收藏的岗位页面 刷新
                                    api.sendEvent({
                                        name: "positionEvent"
                                    });

                                    // 执行失败
                                } else {
                                    toast("收藏失败，稍后再试");

                                    applyFlag = true;
                                    unapplyFlag = false;

                                    $("#apply-btn").removeClass("hide");
                                    $("#unapply-btn").addClass("hide");
                                }
                            });
                        }
                    }
                } else {
                    toLogin();
                }
            });

            // 点击取消收藏
            $("#unapply-btn").click(function() {
                if (isLogin()) {
                    if (unapplyFlag) {
                        if (isNotEmpty(applyIds)) {
                            unapplyFlag = false;

                            var tmpApplyIds = applyIds.split(",");
                            var tmpApplyIdsStr= "";

                            for (var i = 0; i < tmpApplyIds.length; i++) {
                                if (tmpApplyIds.length == 1) {
                                    tmpApplyIdsStr += ("'" + tmpApplyIds[i] + "'");
                                } else {
                                    if (i < (tmpApplyIds.length - 1)) {
                                        tmpApplyIdsStr += ("'" + tmpApplyIds[i] + "',");
                                    } else {
                                        tmpApplyIdsStr += ("'" + tmpApplyIds[i] + "'");
                                    }
                                }
                            }

                            var tmpSql4 = sql4.format(tmpApplyIdsStr);

                            // 取消收藏
                            dbExecute(tmpSql4, true, function(ret, err) {
                                // 执行成功
                                if (isObject(ret) && (ret.statusCode == 0)) {
                                    toast("取消收藏成功");

                                    // 获取收藏 ID
                                    getApplyIds(true);

                                    //发送收藏事件，在 收藏的岗位页面 刷新
                                    api.sendEvent({
                                        name: "positionEvent"
                                    });

                                    // 执行失败
                                } else {
                                    toast("取消收藏失败，稍后再试");

                                    applyFlag = false;
                                    unapplyFlag = true;

                                    $("#apply-btn").addClass("hide");
                                    $("#unapply-btn").removeClass("hide");
                                }
                            });
                        }
                    }
                } else {
                    toLogin();
                }
            });

            // 监听登录事件
            api.addEventListener({
                name: "loginEvent"
            }, function(ret, err) {
                stuInfo = getLoginStudentInfo();

                // 获取收藏 ID
                getApplyIds(true);
                // 获取简历 ID
                getResumeId(true);
                // 获取投简历 ID
                getSendApplyIds(true);
            });
        }
    };
</script>
</body>
</html>